<?php 
$w = $table['ModelTable']['width'];
$h = $table['ModelTable']['height'];

$cellw = 22;
$cellh = 22;
function tr_style($tr,$w = 20,$h = 20){
	if($tr['direct']){
		return "height:{$h}px;width:".$w*$tr['z']."px;top:".$h*$tr['y']."px;left:".$w*$tr['x'].'px';
	}else{
		return "width:{$h}px;height:".$w*$tr['z']."px;top:".$h*$tr['y']."px;left:".$w*$tr['x'].'px';
	}
}
function getTd($tr,$y){
	$res = array('id'=>'','name'=>'','enable'=>0);
	foreach ($tr['ModelTd'] as $td){
		if($td['y'] == $y){
			$res = $td;
			break;
		}
	}
	return $res;
}
?>
<div id = 'seat_map' style = 'width:<?php echo ($w+1)*$cellw?>px;height:<?php echo ($h+1)*$cellh?>px;'>
<div class = 'seat' style = 'width:<?php echo ($w+1)*$cellw?>px;height:<?php echo ($h+1)*$cellh?>px;'>
<?php foreach ($table['ModelTr'] as $tr):?>
<ul class = 'seat_tr seat_tr_<?php echo $tr['id']?>' 
	title = '<?php echo $tr['name']?>'
	style = "<?php echo tr_style($tr,$cellw,$cellh)?>"
	data-id = "<?php echo $tr['id']?>"
	data-value = '<?php //echo json_encode($tr)?>'
	data-pos-x = '<?php echo $tr['x']?>'
	data-pos-y = '<?php echo $tr['y']?>'
>
	<?php for ($i=0;$i<$tr['z'];$i++){?>
		<?php 
		if(isset($tr['ModelTd'])):
			$td = getTd($tr,$i);
			if(empty($td['Seat'])){
				$td['Seat'] = array('id'=>'','seat_type_id'=>'',
					'SeatType'=>array('add_class'=>'','color'=>'','price'=>''),
					'SeatSold'=>array()
				);
			}
			$seat_sold_state = isset($td['Seat']['SeatSold']['ticket_seat_sold_id'])?$td['Seat']['SeatSold']['ticket_seat_sold_id']:0;
			if(!$seat_sold_state)
			$seat_sold_state = $td['Seat']['id']?'sell_seat seat_id_'.$td['Seat']['id']:'';
		?>
		<li class = 'seat_td <?php echo 'seat_is_'.$td['enable']?> <?php echo $td['enable']?'is_seat':'';?> <?php echo $seat_sold_state?> <?php echo $td['Seat']['SeatType']['add_class']?>' 
			style = 'background:<?php echo $td['Seat']['SeatType']['color']?>'
			data-tr = "<?php echo $tr['id']?>"
			data-td = "<?php echo $td['id']?>"
			data-seat = "<?php echo $td['Seat']['id']?>"
			data-seat_type_id = "<?php echo $td['Seat']['seat_type_id']?>"
			data-seat_type = '<?php echo json_encode($td['Seat']['SeatType'])?>'
			data-price = "<?php echo $td['Seat']['SeatType']['price']?>"
			title = '<?php echo $td['name']!=''?$tr['name'].' '.$td['name'].'座':$tr['name']?>'
		><?php //echo $td['name']?>
		<img data-icon = '<?php echo processSeatPic($td)?>' src="seat/img/seat/<?php echo processSeatPic($td)?>">
		</li>
		<?php endif;?>
	<?php }?>
</ul>
<?php endforeach;?>
</div>
</div>


<style>
#seat_map{position:relative;}

#seat_map .seat{background:transparent;position: absolute;z-index: 1;}
#seat_map .seat_tr{margin:0;padding:0;background:lightblue;list-style: none;position:absolute;}
.seat_td{float:left;background:url('seat/img/cellbgTd.png');cursor: pointer;width:<?php echo $cellw ?>px;height:<?php echo $cellh?>px;}
.seat_tr_1{height:<?php echo $cellh?>px}
.seat_is_1{color:black;text-align:center;background:url('seat/img/cellbgSeat.png');moz-user-select: -moz-none;-moz-user-select: none;-o-user-select:none;-khtml-user-select:none;-webkit-user-select:none;-ms-user-select:none;user-select:none;}
		
</style>
